package com.itheima.controller;

import com.itheima.comment.Result;
import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login.do")
    @ResponseBody
    public Result login(@RequestBody User user, HttpServletRequest request){

        Result result = new Result();
        if ("zhangsan".equals(user.getUsername()) && "123".equals(user.getPassword())){
            //登录成功则将user保存到session对象中
            request.getSession().setAttribute("user",user);
            result.setFlag(true);
            return result;
        }
        result.setFlag(false);
        result.setMessage("用户名或密码出错");
        return result;
    }
}
